﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: ShiftMinTo.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2012-09-06 11:39 AM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Collections.Generic;
using System.Linq;

namespace BOL.Linq.Transformation
{
    public static partial class Scaling
    {
        public static IEnumerable<decimal> ShiftMinTo(this IEnumerable<decimal> source, decimal constant)
        {
            var list = source.ToList();
            var min = list.Min();

            return list.Shift(-min + constant);
        }

        public static IEnumerable<double> ShiftMinTo(this IEnumerable<double> source, double constant)
        {
            var list = source.ToList();
            var min = list.Min();

            return list.Shift(-min + constant);
        }

        public static IEnumerable<float> ShiftMinTo(this IEnumerable<float> source, float constant)
        {
            var list = source.ToList();
            var min = list.Min();

            return list.Shift(-min + constant);
        }

        public static IEnumerable<int> ShiftMinTo(this IEnumerable<int> source, int constant)
        {
            var list = source.ToList();
            var min = list.Min();

            return list.Shift(-min + constant);
        }

        public static IEnumerable<long> ShiftMinTo(this IEnumerable<long> source, long constant)
        {
            var list = source.ToList();
            var min = list.Min();

            return list.Shift(-min + constant);
        }

        public static IEnumerable<decimal> ShiftMinTo<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector, decimal constant)
        {
            return source.Select(selector).ShiftMinTo(constant);
        }

        public static IEnumerable<double> ShiftMinTo<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector, double constant)
        {
            return source.Select(selector).ShiftMinTo(constant);
        }

        public static IEnumerable<float> ShiftMinTo<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector, float constant)
        {
            return source.Select(selector).ShiftMinTo(constant);
        }

        public static IEnumerable<int> ShiftMinTo<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector, int constant)
        {
            return source.Select(selector).ShiftMinTo(constant);
        }

        public static IEnumerable<long> ShiftMinTo<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector, long constant)
        {
            return source.Select(selector).ShiftMinTo(constant);
        }
    }
}
